package com.haixiaoke.saas.manage.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.haixiaoke.saas.apartment.domain.ServiceFacilities;
import com.haixiaoke.saas.apartment.service.IServiceFacilitiesService;
import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 服务设施Controller
 *
 * @author qixi
 * @date 2024-05-16
 */
@RestController
@RequestMapping("/manage/apartment/facilities")
public class ManageServiceFacilitiesController extends BaseController {
    @Autowired
    private IServiceFacilitiesService serviceFacilitiesService;

    /**
     * 查询服务设施列表
     */
    @PreAuthorize("@ss.hasPermi('apartment:facilities:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceFacilities serviceFacilities) {
        startPage();
        List<ServiceFacilities> list = serviceFacilitiesService.selectHouseFacilitiesList(serviceFacilities);
        return getDataTable(list);
    }

    /**
     * 导出服务设施列表
     */
    @PreAuthorize("@ss.hasPermi('apartment:facilities:export')")
    @Log(title = "服务设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceFacilities serviceFacilities) {
        List<ServiceFacilities> list = serviceFacilitiesService.selectHouseFacilitiesList(serviceFacilities);
        ExcelUtil<ServiceFacilities> util = new ExcelUtil<ServiceFacilities>(ServiceFacilities.class);
        util.exportExcel(response, list, "服务设施数据");
    }

    /**
     * 获取服务设施详细信息
     */
    @PreAuthorize("@ss.hasPermi('apartment:facilities:query')")
    @GetMapping(value = "/{facilitiesId}")
    public AjaxResult getInfo(@PathVariable("facilitiesId") Long facilitiesId) {
        return success(serviceFacilitiesService.selectHouseFacilitiesByFacilitiesId(facilitiesId));
    }

    /**
     * 新增服务设施
     */
    @PreAuthorize("@ss.hasPermi('apartment:facilities:add')")
    @Log(title = "服务设施", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceFacilities serviceFacilities) {
        return toAjax(serviceFacilitiesService.insertHouseFacilities(serviceFacilities));
    }

    /**
     * 修改服务设施
     */
    @PreAuthorize("@ss.hasPermi('apartment:facilities:edit')")
    @Log(title = "服务设施", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceFacilities serviceFacilities) {
        return toAjax(serviceFacilitiesService.updateHouseFacilities(serviceFacilities));
    }

    /**
     * 删除服务设施
     */
    @PreAuthorize("@ss.hasPermi('apartment:facilities:remove')")
    @Log(title = "服务设施", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilitiesIds}")
    public AjaxResult remove(@PathVariable Long[] facilitiesIds) {
        return toAjax(serviceFacilitiesService.deleteHouseFacilitiesByFacilitiesIds(facilitiesIds));
    }
}
